package com.example.qxfw.dataBaseManager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.qxfw.common.entity.*;
import com.example.qxfw.common.entity.CountryPoint;
import com.example.qxfw.common.entity.CountyPoint;
import com.example.qxfw.common.entity.yj.ImpGoal;
import com.example.qxfw.common.entity.yj.Village;
import com.example.qxfw.common.mapper.*;
import com.example.qxfw.dataBaseManager.service.EmergencyResourcesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/7  星期五   14:05
 * @description : 此类用来
 ***************************************/
@Service
public class EmergencyResourcesServiceImpl implements EmergencyResourcesService {

    @Autowired
    private CountyPointMapperXml countyPointMapperXml;

    @Autowired
    private CountryPointMapperXml countryPointMapperXml;

    @Autowired
    private VillageMapperXml villageMapperXml;

    @Autowired
    private ReservoirMapperXml reservoirMapperXml;

    @Autowired
    private DangerSourceMapperXml dangerSourceMapperXml;

    @Autowired
    private ImpGoalMapperXml impGoalMapperXml;

    @Autowired
    private FloodcontrolProjectMapperXml floodcontrolProjectMapperXml;

    @Autowired
    private PotentialPointsMapperXml potentialPointsMapperXml;

    @Autowired
    private DisasterTypeMapperXml disasterTypeMapperXml;


    @Override
    public List<CountyPoint> getAllCountyPoint() {
        return countyPointMapperXml.getAllOrById(null);
    }

    @Override
    public List<CountryPoint> getAllCountryPoint() {
        return countryPointMapperXml.getAllOrById(null);
    }

    @Override
    public List<Village> getAllVillage() {
        return villageMapperXml.getAllOrById(null);
    }

    @Override
    public Integer selectJudge(String tableName, String name) {
        switch (tableName){
            case "county_point":
                return this.countyPointMapperXml.selectCount(new LambdaQueryWrapper<CountyPoint>()
                        .like(CountyPoint::getName, name));
            case "country_point":
                return this.countryPointMapperXml.selectCount(new LambdaQueryWrapper<CountryPoint>()
                        .like(CountryPoint::getName, name));
            case "village":
                return this.villageMapperXml.selectCount(new LambdaQueryWrapper<Village>()
                        .like(Village::getVillagename, name));
            default:
                return null;
        }
    }

    @Override
    public Integer saveCountyPoint(final CountyPoint countyPoint) {
        return countyPointMapperXml.insertSelective(countyPoint);
    }

    @Override
    public Integer saveCountryPoint(final CountryPoint countryPoint) {
        countryPointMapperXml.insertSelective(countryPoint);
        return countryPointMapperXml.insertSelective(countryPoint);
    }

    @Override
    public Integer saveVillage(final Village village) {
        return villageMapperXml.insertSelective(village);
    }

    @Override
    public Integer updateCountyPoint(final CountyPoint countyPoint) {
        return this.countyPointMapperXml.updateByPrimaryKeySelective(countyPoint);
    }

    @Override
    public Integer updateCountryPoint(final CountryPoint countryPoint) {
        return countryPointMapperXml.updateByPrimaryKeySelective(countryPoint);
    }

    @Override
    public Integer updateVillage(final Village village) {
        return villageMapperXml.updateByPrimaryKeySelective(village);
    }

    @Override
    public Integer selectDelete(final String tableName, final Integer id) {
        switch (tableName){
            case "county_point":
                return this.countyPointMapperXml.deleteById(id);
            case "country_point":
                return this.countryPointMapperXml.deleteById(id);
            case "village":
                return this.villageMapperXml.deleteById(id);
            default:
                return null;
        }
    }

    @Override
    public Integer saveReservoir(final Reservoir reservoir) {
        return this.reservoirMapperXml.insertSelective(reservoir);
    }

    @Override
    public Integer updateReservoir(final Reservoir reservoir) {
        return this.reservoirMapperXml.updateByPrimaryKeySelective(reservoir);
    }

    @Override
    public Integer deleteReservoir(final Integer id) {
        return this.reservoirMapperXml.deleteById(id);
    }

    @Override
    public List<Reservoir> selectReservoirOrderById() {
        return this.reservoirMapperXml.selectList(new LambdaQueryWrapper<Reservoir>()
                .orderByAsc(Reservoir::getId));
    }

    @Override
    public List<Reservoir> getAllReservoir() {
        return this.reservoirMapperXml.selectList(null);
    }


    @Override
    public List<DangerSource> getAllDangerSource() {
        return this.dangerSourceMapperXml.selectList(null);
    }

    @Override
    public List<ImpGoal> getAllImpGoal() {
        return this.impGoalMapperXml.selectList(null);
    }

    @Override
    public List<FloodcontrolProject> getAllFloodControlProject() {
        return this.floodcontrolProjectMapperXml.selectList(null);
    }

    @Override
    public List<PotentialPoints> getAllPotentialPoints() {
        return this.potentialPointsMapperXml.selectList(null);
    }

    @Override
    public List<DisasterType> getAllDisasterType() {
        return this.disasterTypeMapperXml.selectList(null);
    }

    @Override
    public Integer saveDangerSource(final DangerSource dangerSource) {

        return this.dangerSourceMapperXml.insertSelective(dangerSource);
    }

    @Override
    public Integer saveImpGoal(final ImpGoal impGoal) {
        return this.impGoalMapperXml.insertSelective(impGoal);
    }

    @Override
    public Integer saveFloodControlProject(final FloodcontrolProject floodcontrolProject) {
        return this.floodcontrolProjectMapperXml.insertSelective(floodcontrolProject);
    }

    @Override
    public Integer updateDangerSource(final DangerSource dangerSource) {
        return this.dangerSourceMapperXml.updateByPrimaryKeySelective(dangerSource);
    }

    @Override
    public Integer updateImpGoal(final ImpGoal impGoal) {
        return this.impGoalMapperXml.updateByPrimaryKeySelective(impGoal);
    }

    @Override
    public Integer updateFloodControlProject(final FloodcontrolProject floodcontrolProject) {
        return this.floodcontrolProjectMapperXml.updateByPrimaryKeySelective(floodcontrolProject);
    }

    @Override
    public Integer deleteDangerSource(final Integer id) {
        return this.dangerSourceMapperXml.deleteById(id);
    }

    @Override
    public Integer deleteImpGoal(final Integer id) {
        return this.impGoalMapperXml.deleteById(id);
    }

    @Override
    public Integer deleteFloodControlProject(final Integer id) {
        return this.floodcontrolProjectMapperXml.deleteById(id);
    }
}
